// 初始化验证码
var uuid = '';
function captcha() {
    uuid = getUUID();
    $('#captcha').attr('src', './captcha.jpg?uuid=' + uuid)
}
captcha();
$('#captcha').click(function () {
    captcha();
});

$('#login-btn').click(function () {
    var data = {
        username: $('#username-input').val(),
        password: $('#passwd-input').val(),
        captcha: $('#captcha-input').val(),
        uuid: uuid
    };
    axios.post('./sys/login', {
        'data': encrypt(JSON.stringify(data))
        }).then(function (response) {
            console.log(response);
        if(response.data.code === 0) {
            Cookies.set('token', response.data.token, {path: '/'});
            Cookies.set('preview', 'false', {path: '/'});
            setTimeout(function () {
                window.location.href = ctx + './sys.html';
            }, 1000);
        }else {
            captcha();
        }
    }).catch(function (error) {
        captcha();
        console.log(error);
    });
});

function encrypt(data) {
    var jsencrypt = new JSEncrypt();
    jsencrypt.setPublicKey(publicKey);
    var encrypted = jsencrypt.encrypt(data);
    return encrypted
}



